from django.shortcuts import render
from django.shortcuts import HttpResponse
from django.utils.decorators import method_decorator
from django.views.decorators.http import require_http_methods
from django.contrib.auth import authenticate  # 用户验证函数
from django.contrib.auth import login  # 用户登录函数
from django.contrib.auth import logout  # 用户退出登录函数


# Create your views here.
class Accounts:
    """
    账户方法类
    """

    def login(self, request):
        username = "root"
        password = "root"
        login(request,authenticate(username=username,password=password))
        return HttpResponse("登录成功")
    # @method_decorator(require_http_methods(["POST"]))  # 只允许POST方法访问
    # def login(self, request):
    #     username = request.POST.get("username")
    #     password = request.POST.get("password")
    #     user = authenticate(username=username, password=password)
    #     # 如果用户存在且活跃
    #     if user:
    #         if user.is_active:
    #             login(request, user)
    #             return HttpResponse("登录成功")
    #         else:
    #             return HttpResponse("Accounts.login:账号已冻结!")
    #     else:
    #         return HttpResponse("用户不存在")

account_views = Accounts()